<SCRIPT LANGUAGE="JavaScript"> <!-- Beginning of JavaScript - var sum = 0; // global variable to tally the running sum of all the rolls var n = 0; // global variable to count the number of rolls made //========================================================================= function printAverage() { var average; report = "Sorry .... you'll have to write the JavaScript to do it."; libsWin = window.open("","",",width=300,height=250,scrollbars=yes"); libsWin.document.write(report); libsWin.document.close(); } //========================================================================= function rollDice() { var roll; // to hold the value of the rolled die var report; // to hold the "report" we want to print in the window report = "<HEAD><TITLE>Dicey...</TITLE></HEAD>" + "<BODY BGCOLOR = '#FFFFFF'>"; report = report + "<FONT SIZE = 4>" + document.dicey.input1.value + "'s new roll: "; // generate a number between 1 and 6 roll = Math.floor(Math.random()*6 + 1); // add the new roll onto the report report = report + roll + "</FONT><P>"; // add the roll to the sum of previous rolls sum = sum + roll; // add the sum to the report report = report + "<p>The new sum is " + sum + "<p>"; // output the report to a new window libsWin = window.open("","",",width=300,height=250,scrollbars=yes"); libsWin.document.write(report); libsWin.document.close(); } // - End of JavaScript - --> </SCRIPT> <FORM NAME = "dicey"> Your Name: <INPUT TYPE = "TEXT" NAME = "input1"> <p> <INPUT TYPE = "BUTTON" VALUE = "Roll" onClick ="rollDice()"> <p> <INPUT TYPE = "BUTTON" VALUE = "Report Average Roll" onClick ="printAverage()"> </FORM>